package reflection;

/**
 * @author liweimin
 * @date 2021/4/14 14:34
 * @description 静态代理：代理类与被代理类在编译期间就确定下来了
 * @since
 */
public class StaticProxy {

    public static void main(String[] args) {
        ClothFactory nike = new NikeClothFactory();
        ClothFactory lining = new LiNingClothFactory();
        ProxyClothFactory proxyClothFactory = new ProxyClothFactory(nike);
        proxyClothFactory.produce();
        ProxyClothFactory proxyClothFactory1 = new ProxyClothFactory(lining);
        proxyClothFactory1.produce();
    }

}

interface ClothFactory {
    void produce();
}

class ProxyClothFactory implements ClothFactory {
    private ClothFactory clothFactory;

    public ProxyClothFactory(ClothFactory clothFactory) {
        this.clothFactory = clothFactory;
    }

    @Override
    public void produce() {
        System.out.println("-------------------代理类开始--------------------");

        clothFactory.produce();

        System.out.println("-------------------代理类结束--------------------");
    }
}

class LiNingClothFactory implements ClothFactory {

    @Override
    public void produce() {
        System.out.println("李宁生产衣服");
    }
}

class NikeClothFactory implements ClothFactory {

    @Override
    public void produce() {
        System.out.println("Nike生产衣服");
    }
}